package com.heima.d4prac;

import org.junit.jupiter.api.Test;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.util.Calendar;
import java.util.Date;

public class Test2 {
    @Test
    public void test(){
        //当前日期
        LocalTime now0 = LocalTime.now();
        LocalDate now1 = LocalDate.now();
        LocalDateTime now2 = LocalDateTime.now();
        //指定日期
        LocalTime localTime = LocalTime.of(12, 12, 12);
        LocalDate localDate = LocalDate.of(1980, 12, 13);
        LocalDateTime localDateTime = LocalDateTime.of(1975, 9, 16, 5, 6, 9);
        System.out.println(localDateTime.getHour());
        //修改之后原本的时间值不变
        LocalDateTime localDateTime1 = localDateTime.withDayOfMonth(25);
        LocalDateTime localDateTime2 = localDateTime.plusMonths(5);
        System.out.println(localDateTime2);
        LocalDateTime localDateTime3 = localDateTime.minusMinutes(20);
        System.out.println(localDateTime3);
        System.out.println("===========");
        System.out.println(localDateTime);
        Instant now = Instant.now();
        System.out.println(now);
        OffsetDateTime offsetDateTime = now.atOffset(ZoneOffset.ofHours(8));
        System.out.println(offsetDateTime);
        long epochMilli = now.toEpochMilli();
        System.out.println(epochMilli);
    }
    @Test
    public void test1(){
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
        String s1 = dateTimeFormatter.format(now);
        System.out.println(s1);
        TemporalAccessor ta = dateTimeFormatter.parse("2022/12/05 16:04:56");
        LocalDateTime ldt = LocalDateTime.from(ta);
        System.out.println(ldt);
        LocalDateTime ldt1 = LocalDateTime.parse("2022/12/05 16:04:56", dateTimeFormatter);
        System.out.println(ldt1);
    }
    @Test
    public void test2(){
        Calendar instance = Calendar.getInstance();
        //生日
        Date birth0 = instance.getTime();
        System.out.println(birth0);
        //100天以后的日期
        instance.add(Calendar.DATE,100);
        Date time = instance.getTime();
        System.out.println(time);
    }
    @Test
    public void test3(){
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime localDateTime = now.plusDays(100);
        System.out.println(localDateTime    );
    }
}
